//
//  HELCreditHeader.m
//  NursingAssociation
//
//  Created by wsj2015 on 2017/2/21.
//  Copyright © 2017年 wsj2015. All rights reserved.
//

#import "HELCreditHeader.h"
#import "DGSAttributedStringSuite.h"
@implementation HELCreditHeader
{
   
}

- (instancetype)initWithCoder:(NSCoder *)aDecoder{
    
    if (self = [super initWithCoder: aDecoder]) {
        
        
        
    }
    return self;;
    
}
- (IBAction)backAction:(id)sender {
    if (self.backAction) {
        self.backAction();
    }
}
- (IBAction)findHistoryAciton:(id)sender {
    if (self.findHistory) {
        self.findHistory();
    }
}

+ (instancetype)sharedHeader{
  
    HELCreditHeader *header =[[NSBundle mainBundle] loadNibNamed:@"HELCreditHeader" owner:nil options:0].lastObject;
    [header showWave];
    wsj_cornerRadius(header.circleBgView, header.circleBgView.bounds.size.width/2);
    wsj_cornerRadius(header.iner_circle, header.iner_circle.bounds.size.width/2);
    wsj_cornerRadius(header.shenqingBtn, header.shenqingBtn.bounds.size.height/2);
    header.iner_circle.layer.borderWidth = 4;
    header.iner_circle.layer.borderColor = kMainColor.CGColor;
    header.scoreL.attributedText = [NSAttributedString dgs_makeString:^(DGSAttributedStringMaker *add) {
        add.string(@"0").color(kMainColor).fontSize(30);
        add.string(@"学分").color(kMainColor).fontSize(13);
    }];
    return header;
}

- (void)showWave{

//    self.waveView.progress = .6;
//    [self.waveView startAnimation];
 
}
- (IBAction)historyCheck:(id)sender {
    
    if (self.historyCheck) {
        self.historyCheck();
    }
    
    
}
- (void)setCredit:(NSNumber *)credit{

    if ([credit isKindOfClass: [NSNull class]]) {
        credit = @(0);
    }
    
   
    
    
    
    [UIView animateWithDuration:.35 delay:.0 usingSpringWithDamping:.6 initialSpringVelocity:.7 options:UIViewAnimationOptionCurveEaseOut animations:^{
        self.scoreL.transform = CGAffineTransformTranslate(self.scoreL.transform, 0, -30);
        self.scoreL.alpha = 0;
    } completion:^(BOOL finished) {
        self.scoreL.attributedText = [NSAttributedString dgs_makeString:^(DGSAttributedStringMaker *add) {
            add.string([credit stringValue]).color(kMainColor).fontSize(30);
            add.string(@"学分").color(kMainColor).fontSize(13);
        }];
        [UIView animateWithDuration:.35 delay:.0 usingSpringWithDamping:.6 initialSpringVelocity:.7 options:UIViewAnimationOptionCurveEaseOut animations:^{
            self.scoreL.transform = CGAffineTransformIdentity;
             self.scoreL.alpha = 1;
        } completion:^(BOOL finished) {
          
            
            
            
        }];
        
        
    }];
    
    
}
- (IBAction)applyAction:(id)sender {
    
    if (self.apply) {
        self.apply();
    }
  
    
}

@end
